﻿using Carter;
using DDD.Core.Result;
using DDD.GPT;
using Microsoft.AspNetCore.Mvc;

namespace DDD.Api.Endpoints
{
    public class ChatGptEndpoint : ICarterModule
    {

        public void AddRoutes(IEndpointRouteBuilder routeBuilder)
        {
            var group = routeBuilder.MapGroup("api/chatgpt");
            group.MapGet("chat/{message:required}", Chat).WithOpenApi(op =>
            {
                return op;
            });
        }

        /// <summary>
        /// 聊天
        /// </summary>
        /// <param name="message"></param>
        /// <param name="chatGptHttpClient"></param>
        /// <returns></returns>
        private static async Task<ApiResult<string>> Chat(string message, [FromServices] ChatGptHttpClient chatGptHttpClient)
        {
            var result = await chatGptHttpClient.Chat(message);

            return ApiResult<string>.Success(result);
        }

    }
}
